<%@page import="com.dfhc.util.CryptoHelper"%>
<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ taglib uri="/dfhc" prefix="dfhc" %>
<!-- 全局js 和css包 -->
<%@ include file="/jsp/include/web/new/global.jsp" %> 
<html>
<body> 

<!--  获取编码表的下拉列表 -->
 编码表下拉框:<dfhc:select templateId="h_ui_select" size="1" name="directionType" id="yesNot" pleaseSelect="1" 
 defaultValue="0" sqlOption="code" code="RM_YES_NOT" />
<!-- 根据sql查询的列表 -->
自定义sql下拉框:<dfhc:select templateId="h_ui_select" size="1" id="selectUser"  name="selectUser"   sqlOption="SQL"  columnId="id"  columnName="name" sql="select id,name from rm_user" defaultValue=""/> 
 
<!--  按钮 -->
<h4>按钮示例：</h4>
<dfhc:button  templateId="h_ui_update_button"   onclick="alert('更新');"/>
<dfhc:button  templateId="h_ui_add_button"    onclick=""/>
<dfhc:button  templateId="h_ui_search_button"   onclick=""/>
<dfhc:button  templateId="h_ui_delete_button"    onclick=""/>
<!-- 所有按钮模板id:h_ui_div_table_button
h_ui_search_button
h_ui_button_span
h_ui_add_button
h_ui_update_button
h_ui_delete_button
h_ui_div_pop_up_button
h_ui_submit_button
h_ui_save_button
h_ui_exec_button
h_ui_detail_button
h_ui_resetpassword_button
h_ui_back_button
h_ui_reset_button
h_ui_author_button
h_ui_achieve_button
h_ui_export_button
h_ui_sava_button
h_ui_cancel_button
h_ui_newadd_button
h_ui_updateThisPartyName_button
h_ui_updateOrderCode_button
h_ui_insertChildNode_button
h_ui_relationChildNode_button
h_ui_deleteChildNode_button
h_ui_deleteChildRelation_button
h_ui_addViewRootNode_button
h_ui_authorization_button
h_ui_relateViewRootNode_button
h_ui_div_pop_up_button2
h_ui_maintain_button --> 
<!--  列表 -->
<h4>表格示例：</h4>
	<form name="searchForm" id="searchForm" action="">
	<dfhc:div templateId="h_ui_div_search">
		<dfhc:input templateId="h_ui_search_input" placeholder="输入xxx、xxx、xxx" id="" name="searchName"/>
		<dfhc:button templateId="h_ui_search_button" id="" name="" onclick="javascript:_searchData($('.table-sort').DataTable());" />
	</dfhc:div>
	</form>

<dfhc:table templateId="table_h_ui" >    	
		<dfhc:thead>
			<dfhc:tr> 
				<dfhc:th width="25">
				   <dfhc:checkbox name="allId" />
				</dfhc:th>	
				
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" >名称:</dfhc:title>
				</dfhc:th>
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" >登录ID:</dfhc:title>
				</dfhc:th>
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" >邮箱:</dfhc:title>
				</dfhc:th>
				
			</dfhc:tr>
    	   </dfhc:thead>			
		</dfhc:table>          
  
<!--   radio -->
<dfhc:radio   name=""  id=""   value=""  templateId="radio"  checked="checked" />
<!--   checkbox -->
<dfhc:checkbox  name=""  id=""   value="" templateId="checkbox"   checked="checked" />
 


<script type="text/javascript">
var neww;
var newh;
var _table;

$(function(){

	_table = $('.table-sort').dataTable({	
	     dom: 'Zlfrtip',	 
	     
		 ajax : function(data, callback, settings) {
		       var param =  splitParameter(data); 
		       
                 $.ajax({  
                        type: "GET",  
                        url: getRootPath()+'<%=CryptoHelper.encryptUrl(request,"/testController/ajaxUserList")%>',  
                        cache : false,  //禁用缓存  
                        data:param,   
                        dataType: "json",  
                        success: function(result) {  
                                //异常判断与处理  
                                if (result.status=='0') {  
                                    alert(result.message);  
                                    return;  
                                }  
                                //封装返回数据  
                                var returnData = {};  
                                returnData.draw = data.draw;//这里直接自行返回了draw计数器,应该由后台返回  
                                returnData.recordsTotal = result.recordsTotal;//总记录数  
                                returnData.recordsFiltered = result.recordsTotal;//后台不实现过滤功能，每次查询均视作全部结果  
                                returnData.data = result.data;  
                                //调用DataTables提供的callback方法，代表数据已封装完成并传回DataTables进行渲染  
                                //此时的数据需确保正确无误，异常判断应在执行此回调前自行处理完毕  
                                callback(returnData);  
                                //更新总记录数
                                $("#totalRecodSpan").html('共有数据：<strong>'+result.recordsTotal+'</strong> 条</span>');
                        },  
                        error: function(XMLHttpRequest, textStatus, errorThrown) {  
                            alert("查询失败");  
                        }  
                    });   
            },  
		"columns": [
		  {
		    "data":"id",
			"render":function(data,type,row,meta){
			   var content='<input type="checkbox" name="allId" value="'+row.id+'"/>';
			   return content; 
			}
		  },
		  {"data":"name"},
		  {"data":"loginId"},
		  {"data":"email"}		  	  
		],
		"columnDefs": [ {"searchable": false,
            "orderable": false,
            "targets": 0 }]  				
	});
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
});
/*拼接参数*/
function splitParameter(data){
	 //var paramJsonStr = formToJson(decodeURIComponent($(searchForm).serialize(),true));
	 var paramJsonStr = $(searchForm).serializeObject();
	 //组装 排序参数
	 if(data.order && data.order.length && data.order[0]){
	  data.sort = data.columns[data.order[0].column].data;
      if(data.sort!='0'){
      	data.dir = data.order[0].dir;
      }else{
        data.sort ='';
        data.dir='';
      }
	}  
	var retVal;
	retVal = $.extend( {}, data,paramJsonStr); 
	return retVal;
}


$.fn.serializeObject=function(){
    var o = {};
    var a = this.serializeArray();
    $.each(a, function() {
        if (o[this.name] !== undefined) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};
function todelete(url){
	debugger;
	var len = $('input[name="allId"]:checked').length;
    var count=0;
    var ids='';
     $('input[name="allId"]:checked').each(function(){     	
     	var dataId =$(this).val();
     	if(dataId !== undefined && dataId!='on'){
     		ids+=dataId
         	if(len!=1){
         		ids+=","
         	}
         	count++;
     	}
     });  
    if(count==0){
       alert("请选择删除的记录!");
       return;
    }  
    if(count>1){
       alert("只能选择一条记录!");
       return;	
    }
    var newUrl ;
    if(url.indexOf("?")>=0){
    	newUrl = url+'&id='+ids;
    }else{
    	newUrl = url+'?id='+ids;
    }
    
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'POST',
			url: newUrl,
			dataType: 'json',
			success: function(data){
				//$(obj).parents("tr").remove();
				layer.msg('已删除!',{icon:1,time:1000});
				$('.table-sort').DataTable().ajax.reload();
			},
			error:function(data) {
				console.log(data.msg);
			},
		});		
	});
}
</script>

</body>
</html>